import BaseXform from '../base-xform';

class BaseCellAnchorXform extends BaseXform {
    parseOpen(node) {
        if (this.parser) {
            this.parser.parseOpen(node);
            return true;
        }
        switch (node.name) {
            case this.tag:
                this.reset();
                this.model = {
                    range: {
                        editAs: node.attributes.editAs || 'oneCell',
                    },
                };
                break;
            default:
                this.parser = this.map[node.name];
                if (this.parser) {
                    this.parser.parseOpen(node);
                }
                break;
        }
        return true;
    }

    parseText(text) {
        if (this.parser) {
            this.parser.parseText(text);
        }
    }

    reconcilePicture(model, options) {
        if (model && model.rId) {
            const rel = options.rels[model.rId];
            const match = rel.Target.match(/.*\/media\/(.+[.][a-zA-Z]{3,4})/);
            if (match) {
                const name = match[1];
                const mediaId = options.mediaIndex[name];
                return options.media[mediaId];
            }
        }
        return undefined;
    }
}

export default BaseCellAnchorXform;
